package util

import (
	"errors"
)

type (
	Table struct {
		Name   string   `json:"name"`
		Desc   string   `json:"desc"`
		Fields []*Field `json:"fields"`
	}
	Field struct {
		Name string `json:"name"`
		Type string `json:"type"`
		Desc string `json:"desc"`
	}
	Db interface {
		GetTables() ([]*Table, error)
	}
)

func ConnectDb(dbType, link string) (Db, error) {
	var (
		db  Db
		err error
	)
	switch dbType {
	case "mysql":
		db, err = NewMysql(link)
	//case "postgres":
	//	dialector = postgres.Open(link)
	//case "sqlite":
	//	dialector = sqlite.Open(link)
	//case "sqlserver":
	//	fallthrough
	//case "mssql":
	//	dialector = sqlserver.Open(link)
	default:
		return nil, errors.New("unsupported database type: " + dbType)
	}
	return db, err
}
